<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>
<style type="text/css">
	table{border-collapse: collapse;border: none;}
	td{ border: solid #000 1px;}
	thead th{background-color: #000000;}
	thead th a{color: red}
	tbody tr th a{color: red}
	.mytable th{ text-align: center;}
</style>
<div>
	<select onchange="location.href='/?issue=' + this.value">
		<?
			foreach ($issue as $key => $value) {
				if($value->issue==$currentIssue){
		?>
			<option value='<?=$value->issue?>' selected><?=$value->issue?></option>
		<?
				}
				else{
		?>
			<option value='<?=$value->issue?>'><?=$value->issue?></option>
		<?
				}
			}
		?>
	</select>
</div>
<div>
	<input type="checkbox" id="chkAll" checked/>全选&nbsp;<input type="checkbox" value="" id="chk5"/>五大联赛
	<br/>
	<?
	foreach ($gameTypeList as $key => $value) {
	?>
		<input type="checkbox" value="<?=$value->gametype?>" class="chkGameType" checked/><?=$value->gametype?>
	<?
	}
	?>
</div>
<table class="mytable" id="myTable" width="100%">
	<thead>
		<tr style="background-color:#000000; text-align:center; color:white;border-right:1px solid #3E3E3E;border-bottom:1px solid #3E3E3E;line-height:20px;">
			<th align="center">序号</th>
			<!--<th align="center">编号</th>-->
			<th align="center">时间</th>
			<th align="center">赛事</th>
			<th align="center">球队&nbsp;<input type="checkbox" class="chkKing"/><span class="new_record icon_king"></span></th>
			<th align="center">比分</th>
			<th align="center">&nbsp;</th>
			<!--<th align="center">荐&nbsp;&nbsp;<a href="index.php?r=site/help" target="_blank">帮助</a></th>-->
			<th align="center" title="红底：赔率低于自算；蓝字：赔率低于威廉希尔；红底并白字：赔率均低于自算和威廉希尔">欧赔<br/>平均</th>
			<th align="center">返还<br/>率</th>
			<th align="center">威廉<br/>希尔</th>
			<th align="center">返还<br/>率</th>
			<th align="center">必发<br/>价位</th>
			<th align="center">成交<br/>比例</th>
			<th align="center">必发<br/>成交</th>
			<th align="center">必发<br/>指数</th>
			<th align="center">自算<br/>赔率</th>
			<th align="center">概率<br/>五大</th>
			<th align="center">概率<br/>（同）</th>
			<th align="center">欧赔<br/>凯利</th>
			<th align="center">威廉<br/>凯利</th>
			<!--<th align="center">必发<br/>凯利</th>-->
			<th align="center">赔率<br/>差异</th>
			<th align="center">凯利<br/>差异</th>
			<th align="center">离散</th>
			
		</tr>
	</thead>
	<tbody>
	<?
		foreach ($model as $key => $value) {
			$euroodds3=$value->euroodds3;
			$euroodds1=$value->euroodds1;
			$euroodds0=$value->euroodds0;

			$euroodds3w=$value->euroodds3w;
			$euroodds1w=$value->euroodds1w;
			$euroodds0w=$value->euroodds0w;

			//返还率
			$fanhuanlvEuro=0;
			if($euroodds3>0){
				$fanhuanlvEuro = $euroodds3*$euroodds1*$euroodds0 / ($euroodds3*$euroodds1+$euroodds1*$euroodds0+$euroodds3*$euroodds0);
			}
			
			$fanhuanlvW=0;
			if($euroodds3w>0){
				$fanhuanlvW = $euroodds3w*$euroodds1w*$euroodds0w / ($euroodds3w*$euroodds1w+$euroodds1w*$euroodds0w+$euroodds3w*$euroodds0w);
			}
			

			$myodds3=$value->winprobability>0?$fanhuanlvW/$value->winprobability:0;
			$myodds1=$value->drawprobability>0?$fanhuanlvW/$value->drawprobability:0;
			$myodds0=$value->loseprobability>0?$fanhuanlvW/$value->loseprobability:0;

			$euroodds3Class="";
			$euroodds1Class="";
			$euroodds0Class="";

			if($euroodds3<$euroodds3w && $euroodds3<$myodds3){
				$euroodds3Class="bred_fwhite";
			}
			else if($euroodds3<$euroodds3w){
				$euroodds3Class="white";
			}
			else if($euroodds3<$myodds3){
				$euroodds3Class="bred";
			}

			if($euroodds1<$euroodds1w && $euroodds1<$myodds1){
				$euroodds1Class="bred_fwhite";
			}
			else if($euroodds1<$euroodds1w){
				$euroodds1Class="white";
			}
			else if($euroodds1<$myodds1){
				$euroodds1Class="bred";
			}

			if($euroodds0<$euroodds0w && $euroodds0<$myodds0){
				$euroodds0Class="bred_fwhite";
			}
			else if($euroodds0<$euroodds0w){
				$euroodds0Class="white";
			}
			else if($euroodds0<$myodds0){
				$euroodds0Class="bred";
			}

			//欧赔平均凯利
			$avgoddskl3=$euroodds3*$value->winprobability*100;
			$avgoddskl1=$euroodds1*$value->drawprobability*100;
			$avgoddskl0=$euroodds0*$value->loseprobability*100;

			//威廉希尔凯利
			$woddskl3=$euroodds3w*$value->winprobability*100;
			$woddskl1=$euroodds1w*$value->drawprobability*100;
			$woddskl0=$euroodds0w*$value->loseprobability*100;

			//赔率差异
			$chayi3='100';
			$chayi1='100';
			$chayi0='100';
			if($fanhuanlvEuro>0&&$fanhuanlvW>0){
				if($euroodds3>0&&$euroodds3w>0){
					$chayi3=($euroodds3/$fanhuanlvEuro-$euroodds3w/$fanhuanlvW)/($euroodds3/$fanhuanlvEuro+$euroodds3w/$fanhuanlvW);
				}
				
				if($euroodds1>0&&$euroodds1w>0){
					$chayi1=($euroodds1/$fanhuanlvEuro-$euroodds1w/$fanhuanlvW)/($euroodds1/$fanhuanlvEuro+$euroodds1w/$fanhuanlvW);
				}
				
				if($euroodds0>0&&$euroodds0w>0){
					$chayi0=($euroodds0/$fanhuanlvEuro-$euroodds0w/$fanhuanlvW)/($euroodds0/$fanhuanlvEuro+$euroodds0w/$fanhuanlvW);
				}
			}

			//凯利差异
			$chayikl3=$avgoddskl3+$woddskl3==0?'100':($avgoddskl3-$woddskl3)/($avgoddskl3+$woddskl3);
			$chayikl1=$avgoddskl1+$woddskl1==0?'100':($avgoddskl1-$woddskl1)/($avgoddskl1+$woddskl1);
			$chayikl0=$avgoddskl0+$woddskl0==0?'100':($avgoddskl0-$woddskl0)/($avgoddskl0+$woddskl0);

			//是否推荐
			//第一种推荐的算法
			$jian3='';
			$jian1='';
			$jian0='';

			if($myodds3!=0&&$myodds1!=0&&$myodds0!=0){
				//第一种推荐的算法
				$jian3=$avgoddskl3<100&&$woddskl3<100?'<span class="new_record icon_star"></span>':'';
				$jian1=$avgoddskl1<100&&$woddskl1<100?'<span class="new_record icon_star"></span>':'';
				$jian0=$avgoddskl0<100&&$woddskl0<100?'<span class="new_record icon_star"></span>':'';

				//第二种推荐的算法（如果赔率差异和凯利差异相差不超过0.01）
				$jian3=abs($chayi3-$chayikl3)<0.01?'<span class="new_record icon_star"></span>'.$jian3:$jian3;
				$jian1=abs($chayi1-$chayikl1)<0.01?'<span class="new_record icon_star"></span>'.$jian1:$jian1;
				$jian0=abs($chayi0-$chayikl0)<0.01?'<span class="new_record icon_star"></span>'.$jian0:$jian0;
				
				//第三种推荐的算法（如果欧赔凯利小于等于威廉希尔凯利，并且赔率差异等于凯利差异）
				$jian3=$avgoddskl3<=$woddskl3&&(sprintf("%.2f", $chayi3)==sprintf("%.2f", $chayikl3))?'<span class="new_record icon_star"></span>'.$jian3:$jian3;
				$jian1=$avgoddskl1<=$woddskl1&&(sprintf("%.2f", $chayi1)==sprintf("%.2f", $chayikl1))?'<span class="new_record icon_star"></span>'.$jian1:$jian1;
				$jian0=$avgoddskl0<=$woddskl0&&(sprintf("%.2f", $chayi0)==sprintf("%.2f", $chayikl0))?'<span class="new_record icon_star"></span>'.$jian0:$jian0;
				
				//第四种推荐的算法（威廉希尔小于自算赔率）
				$jian3=$value->euroodds3w<=$myodds3?'<span class="new_record icon_star"></span>'.$jian3:$jian3;
				$jian1=$value->euroodds1w<=$myodds3?'<span class="new_record icon_star"></span>'.$jian1:$jian1;
				$jian0=$value->euroodds0w<=$myodds3?'<span class="new_record icon_star"></span>'.$jian0:$jian0;
				
				//第五种算法（欧赔小于威廉希尔）
				$jian3=$value->euroodds3<=$value->euroodds3w?'<span class="new_record icon_star"></span>'.$jian3:$jian3;
				$jian1=$value->euroodds1<=$value->euroodds1w?'<span class="new_record icon_star"></span>'.$jian1:$jian1;
				$jian0=$value->euroodds0<=$value->euroodds0w?'<span class="new_record icon_star"></span>'.$jian0:$jian0;				
			}

			//离散值
			$discretevalue3=$value->discretevalue3*100;
			$discretevalue1=$value->discretevalue1*100;
			$discretevalue0=$value->discretevalue0*100;

			$isKing = 0;
			//是否有皇冠
			if($discretevalue3<100&&$discretevalue1>100&&$discretevalue0>100){
				$isKing = 1;
			}
			else if($discretevalue1<100&&$discretevalue3>100&&$discretevalue0>100){
				$isKing = 1;
			}
			else if($discretevalue0<100&&$discretevalue3>100&&$discretevalue1>100){
				$isKing = 1;
			}

			//必发数据计算
			$bfprice3=$value->bfprice3;//胜赔
			$bfprice1=$value->bfprice1;//平赔
			$bfprice0=$value->bfprice0;//负赔

			$bfexchange3 = $value->bfexchange3;//交易量胜
			$bfexchange1 = $value->bfexchange1;//交易量平
			$bfexchange0 = $value->bfexchange0;//交易量负
			$bfexchangeAll = $bfexchange3+$bfexchange1+$bfexchange0;

			$bfexchangeBili3=0;
			$bfexchangeBili1=0;
			$bfexchangeBili0=0;
			$bfexchangekl3=0;
			$bfexchangekl1=0;
			$bfexchangekl0=0;
			if($bfexchangeAll!=0){
				$bfexchangeBili3=$bfexchange3/$bfexchangeAll;//交易比例胜
				$bfexchangeBili1=$bfexchange1/$bfexchangeAll;//交易比例平
				$bfexchangeBili0=$bfexchange0/$bfexchangeAll;//交易比例负

				$bfexchangekl3=$bfprice3*$bfexchangeBili3*100;//凯利胜
				$bfexchangekl1=$bfprice1*$bfexchangeBili1*100;//凯利胜
				$bfexchangekl0=$bfprice3*$bfexchangeBili0*100;//凯利胜
			}

			$fanhuanlvbf=0;
			if($bfprice3>0&&$bfprice1>0&&$bfprice0>0){
				$fanhuanlvbf = $bfprice3*$bfprice1*$bfprice0 / ($bfprice3*$bfprice1+$bfprice1*$bfprice0+$bfprice3*$bfprice0);
			}

			//根据必发交易比例和威廉希尔返还率，自算参考赔率
			$mybfodds3=0;
			$mybfodds1=0;
			$mybfodds0=0;
			if($fanhuanlvbf>0){
				$mybfodds3=$fanhuanlvW/$bfexchangeBili3;
				$mybfodds1=$fanhuanlvW/$bfexchangeBili1;
				$mybfodds0=$fanhuanlvW/$bfexchangeBili0;
			}

			//必发指数=赔率*成交/总成交
			$bfzhishu3=0;
			$bfzhishu1=0;
			$bfzhishu0=0;
			if($bfexchangeAll>0){
				$bfexchangeAllliangjia=($bfprice3*$bfexchange3+$bfprice1*$bfexchange1+$bfprice0*$bfexchange0);
				$bfzhishu3=$bfprice3*$bfexchange3/$bfexchangeAllliangjia;
				$bfzhishu1=$bfprice1*$bfexchange1/$bfexchangeAllliangjia;
				$bfzhishu0=$bfprice0*$bfexchange0/$bfexchangeAllliangjia;
			}
	?>
	<tr style="background-color:#CCE8CF" gameType="<?=$value->gametype?>" isKing="<?=$isKing?>">
		<td rowspan="6" align="center"><?=$value->gameindex?></td>
		<!--<td rowspan="3"><?=$value->gameid?></td>-->
		<td rowspan="6"><?=date('Y-m-d',strtotime($value->gametime));?><br/><?=date('H:i',strtotime($value->gametime));?></td>
		<td rowspan="6"><?=$value->gametype?></td>
		<td rowspan="2">
		<?
			if($value->winprobability_samegametype==1){
		?>
			<span class="new_record icon_diamond"></span>
		<?
			}
		if($discretevalue3<100&&$discretevalue1>100&&$discretevalue0>100){
		?>
			<span class="new_record icon_king"></span>
		<?=$value->hometeam?>
		<?
			if($chayi3>=0&&$chayikl3>=0){
		?>
		<span style="color:blue">冷</span>
		<?
			}
		}
		else{
		?>
		<?=$value->hometeam?>
		<?
		}
		?>
		</td>
		<td rowspan="2"><?=$value->homegoal!=-1&&$value->homegoal>$value->awaygoal?$value->homegoal.':'.$value->awaygoal:'&nbsp;'?></td>
		<td rowspan="2"><span class="<?=$value->homegoal!=-1&&$value->homegoal>$value->awaygoal?'red':'&nbsp;'?>">胜<span></td>
		<!--<td><?=$jian3?></td>-->
		<td style="background-color:#C0C0C0" class="<?=$euroodds3Class?>"><?=sprintf("%.2f", $euroodds3)?></td>
		<td><?=sprintf("%.2f", $fanhuanlvEuro)?></td>
		<td style="background-color:#C0C0C0" class="<?=$value->euroodds3w<=$myodds3 && $myodds3!=0?"bred":""?>"><span><?=sprintf("%.2f", $value->euroodds3w)?></span></td>
		<td><?=sprintf("%.2f", $fanhuanlvW)?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfprice3)?></td>
		<td><?=sprintf("%.2f", $bfexchangeBili3*100)?>%</td>
		<td style="text-align:right"><?=number_format(sprintf("%.0f", $bfexchange3))?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfzhishu3)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $myodds3)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->winprobability*100)?>%</td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->winprobability_samegametype*100)?>%</td>
		<td><?=sprintf("%.2f", $avgoddskl3)?></td>
		<td><?=sprintf("%.2f", $woddskl3)?></td>
		<!--<td><?=sprintf("%.2f", $bfexchangekl3)?></td>-->
		<td><?=sprintf("%.4f", $chayi3)?></td>
		<td><?=sprintf("%.4f", $chayikl3)?></td>
		<td><?=sprintf("%.2f", $discretevalue3)?></td>
		
	</tr>
	<tr style="background-color:#CCE8CF" gameType="<?=$value->gametype?>" isKing="<?=$isKing?>">
		<td rowspan="2">
		<?
			if($value->drawprobability_samegametype==1){
		?>
			<span class="new_record icon_diamond"></span>
		<?
			}
		if($discretevalue1<100&&$discretevalue3>100&&$discretevalue0>100){
		?>
		<span class="new_record icon_king"></span>
		<?
			if($chayi1>=0&&$chayikl1>=0){
		?>
		<span style="color:blue">冷</span>
		<?
			}
		}
		else{
		?>
		
		<?
		}
		?>
		</td>
		<td rowspan="2"><?=$value->homegoal!=-1&&$value->homegoal==$value->awaygoal?$value->homegoal.':'.$value->awaygoal:'&nbsp;'?></td>
		<td rowspan="2"><span class="<?=$value->homegoal!=-1&&$value->homegoal==$value->awaygoal?'red':'&nbsp;'?>">平<span></td>
		<!--<td><?=$jian1?></td>-->
		<td style="background-color:#C0C0C0" class="<?=$euroodds1Class?>"><?=sprintf("%.2f", $value->euroodds1)?></td>
		<td><?=sprintf("%.2f", $fanhuanlvEuro)?></td>
		<td style="background-color:#C0C0C0" class="<?=$value->euroodds1w<=$myodds1 && $myodds1!=0?"bred":""?>"><span><?=sprintf("%.2f", $value->euroodds1w)?></span></td>
		<td><?=sprintf("%.2f", $fanhuanlvW)?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfprice1)?></td>
		<td><?=sprintf("%.2f", $bfexchangeBili1*100)?>%</td>
		<td style="text-align:right"><?=number_format(sprintf("%.0f", $bfexchange1))?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfzhishu1)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $myodds1)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->drawprobability*100)?>%</td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->drawprobability_samegametype*100)?>%</td>
		<td><?=sprintf("%.2f", $avgoddskl1)?></td>
		<td><?=sprintf("%.2f", $woddskl1)?></td>
		<!--<td><?=sprintf("%.2f", $bfexchangekl1)?></td>-->
		<td><?=sprintf("%.4f", $chayi1)?></td>
		<td><?=sprintf("%.4f", $chayikl1)?></td>
		<td><?=sprintf("%.2f", $discretevalue1)?></td>
		
	</tr>
	<tr style="background-color:#CCE8CF" gameType="<?=$value->gametype?>" isKing="<?=$isKing?>">
		<td rowspan="2">
		<?
			if($value->loseprobability_samegametype==1){
		?>
			<span class="new_record icon_diamond"></span>
		<?
			}
			if($discretevalue0<100&&$discretevalue3>100&&$discretevalue1>100){
			?>
		<span class="new_record icon_king"></span>
		<?=$value->awayteam?>
		<?
			if($chayi0>=0&&$chayikl0>=0){
		?>
		<span style="color:blue">冷</span>
		<?
			}
		}
		else{
		?>
		<?=$value->awayteam?>
		<?
		}
		?>
		</td>
		<td><?=$value->homegoal!=-1&&$value->homegoal<$value->awaygoal?$value->homegoal.':'.$value->awaygoal:'&nbsp;'?></td>
		<td><span class="<?=$value->homegoal!=-1&&$value->homegoal<$value->awaygoal?'red':'&nbsp;'?>">负<span></td>
		<!--<td><?=$jian0?></td>-->
		<td style="background-color:#C0C0C0" class="<?=$euroodds0Class?>"><?=sprintf("%.2f", $value->euroodds0)?></td>
		<td><?=sprintf("%.2f", $fanhuanlvEuro)?></td>
		<td style="background-color:#C0C0C0" class="<?=$value->euroodds0w<=$myodds0 && $myodds0!=0?"bred":""?>"><span><?=sprintf("%.2f", $value->euroodds0w)?></span></td>
		<td><?=sprintf("%.2f", $fanhuanlvW)?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfprice0)?></td>
		<td><?=sprintf("%.2f", $bfexchangeBili0*100)?>%</td>
		<td style="text-align:right"><?=number_format(sprintf("%.0f", $bfexchange0))?></td>
		<td style="text-align:right"><?=sprintf("%.2f", $bfzhishu0)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $myodds0)?></td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->loseprobability*100)?>%</td>
		<td style="background-color:#C0C0C0"><?=sprintf("%.2f", $value->loseprobability_samegametype*100)?>%</td>
		<td><?=sprintf("%.2f", $avgoddskl0)?></td>
		<td><?=sprintf("%.2f", $woddskl0)?></td>
		<!--<td><?=sprintf("%.2f", $bfexchangekl0)?></td>-->
		<td><?=sprintf("%.4f", $chayi0)?></td>
		<td><?=sprintf("%.4f", $chayikl0)?></td>
		<td><?=sprintf("%.2f", $discretevalue0)?></td>
	</tr>
	<?
		}
	?>
	</tbody>
</table>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.fixedtableheader.min.js"></script>
<script type="text/javascript">
	$(function () {
        $("#myTable").fixedtableheader({ highlightrow: true, highlightclass: "stab0", headerrowsize: 1 });
    });

    $(document).ready(function(){
    	//全选
    	$("#chkAll").click(function(){
    		if($(this).attr("checked")=="checked"){
    			$("tr[gameType").show();
    			$(".chkGameType").attr("checked", true);
    		}
    		else{
    			$("tr[gameType").hide();
    			$(".chkGameType").attr("checked", false);
    		}
    	});

    	//五大联赛
    	$("#chk5").click(function(){
    		if($(this).attr("checked")=="checked"){
    			$("tr[gameType]").each(function(){
    				if($(this).attr("gameType")=="英超"||
    					$(this).attr("gameType")=="德甲"||
    					$(this).attr("gameType")=="西甲"||
    					$(this).attr("gameType")=="法甲"||
    					$(this).attr("gameType")=="意甲"){
    					$(this).show();
    					$("#chkAll").attr("checked", false);
    					$(".chkGameType").attr("checked", false);
    				}
    				else{
    					$(this).hide();
    				}
    			});
    		}
    		else{
    			$("tr").show();
    			$("#chkAll").attr("checked", true);
    			$(".chkGameType").attr("checked", true);
    		}
    	});

    	$(".chkGameType").click(function(){
    		if($(this).attr("checked")=="checked"){
    			$("tr[gameType="+$(this).attr("value")+"]").show();
    		}
    		else{
    			$("tr[gameType="+$(this).attr("value")+"]").hide();
    			$("#chkAll").attr("checked", false);
    		}
    	});

    	$(".chkKing").click(function(){
    		if($(this).attr("checked")=="checked"){
    			$("tr[isKing=0]").hide();
    			$("tr[isKing=1]").show();
    		}
    		else{
    			$("tr[gameType]").show();
    		}
    	});
    });
</script>